/*
 * GroceryStore.java
 *
 * Created on October 22, 2007, 12:45 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package grocerystore;

//import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import simulationengine.animation.AnimationCommand;
import simulationengine.animation.AnimationEngine;
import simulationengine.process.Producer;
import simulationengine.process.Resource;
import simulationengine.process.Distribution;

/**
 *
 * @author Eric Drucker
 */
public class GroceryStore
{
    	/** Creates a new instance of GroceryStore */
	public GroceryStore()
	{

	}
		
	public static void main(String args[])
	{
             final int endOfSimulation = 100000;

             Arrival arriveTimeDistribution = new Arrival();
             Service serviceTimeDistribution = new Service();

             Resource checkoutLane = new Resource(serviceTimeDistribution,0);

		   //LinkedBlockingQueue<AnimationCommand> commands = new LinkedBlockingQueue<AnimationCommand>();
                    PriorityBlockingQueue<AnimationCommand> commands = new PriorityBlockingQueue<AnimationCommand>();
		   
             Producer customers = new Producer(endOfSimulation, arriveTimeDistribution, checkoutLane, commands);
             
             System.out.println("Starting Simulation");

		   
             customers.start();

		   int [] serviceLocations = {1};
		   AnimationEngine a = new AnimationEngine("Grocery Store", commands, endOfSimulation, serviceLocations);
	}
        
        public static class Arrival extends simulationengine.process.Distribution
        {
            public Arrival()
            {
                super();
            }
            
            public synchronized int next()
            {
                randInt = rand.nextInt(999);
                if(randInt > 875 || randInt == 0)
                        time += 8;
                else if (randInt > 750)
                        time += 7;
                else if (randInt > 625)
                        time += 6;
                else if (randInt > 500)
                        time += 5;
                else if (randInt > 375)
                        time += 4;
                else if (randInt > 250)
                        time += 3;
                else if (randInt > 125)
                        time += 2;
                else
                        time += 1;
            
                return time;
            }
        }
         
        public static class Service extends simulationengine.process.Distribution
        {
            public Service()
            {
                super();
            }
            
            public int next()
            {
                int randInt = rand.nextInt(99);
                if(randInt > 95 || randInt == 0)
                            time = 6;
                    else if (randInt > 85)
                            time = 5;
                    else if (randInt > 60)
                            time = 4;
                    else if (randInt > 30)
                            time = 3;
                    else if (randInt > 10)
                            time = 2;
                    else
                            time = 1;
            
                return time;
            }
        }
}